package com.dd.cloud.user.service.mechan.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.user.entity.mechan.MechanRankApply;
import com.dd.cloud.user.mapper.mechan.MechanRankApplyMapper;
import com.dd.cloud.user.mapper.mechan.MechanRankMapper;
import com.dd.cloud.user.req.mechan.MechanInfoReviewReq;
import com.dd.cloud.user.service.mechan.IMechanRankApplyService;
import com.dd.cloud.common.exception.ZekeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Lx
 * @version 1.0
 */
@Slf4j
@Service
public class MechanRankApplyServiceImpl extends ServiceImpl<MechanRankApplyMapper, MechanRankApply> implements IMechanRankApplyService {
    @Autowired
    private MechanRankMapper mechanRankMapper;


    /**
     * 审核机构信息-修改审核记录
     *
     * @param req
     * @return
     */
    @Override
    public MechanRankApply reviewMechanRankApply(MechanInfoReviewReq req) {
        QueryWrapper<MechanRankApply> qw = new QueryWrapper<>();
        qw.lambda().eq(MechanRankApply::getId, req.getApplyId());
        qw.lambda().eq(MechanRankApply::getMechanId, req.getMechanId());
        MechanRankApply mechanRankApply = getOne(qw);
        if (mechanRankApply == null) {
            throw new ZekeException(400, "机构审核记录不存在");
        }
        MechanRankApply update = new MechanRankApply();
        update.setId(req.getApplyId());
        update.setStatus(req.getStatus());
        updateById(update);
        return mechanRankApply;
    }
}
